<template>
	<div class="app-container" v-loading="loading">
		<template v-if="flag">
			<div class="content" key="outside">
				<div class="aside">
					<div class="tree-header">
						<span><svg-icon icon-class="type" class-name='type-class'/>&nbsp;&nbsp;文章类别</span>
						<el-button
							type="primary"
							icon="el-icon-plus"
							size="mini"
							@click="handleAdd"
						>新增类别
						</el-button>
					</div>
					<el-tree class="tree" :data="dataTree" node-key="typeId"
							 :highlight-current="true" :expand-on-click-node="false">
						<span class="custom-tree-node" slot-scope="{ node, data }" @click="handleClickNode(data)">
							<span>
								<svg-icon style="width:14px;height:14px;margin-right:5px" icon-class="file-close"
										  v-show="!node.isLeaf && !node.expanded"></svg-icon>
								<svg-icon style="width:14px;height:14px;margin-right:5px" icon-class="file-open"
										  v-show="!node.isLeaf && node.expanded"></svg-icon>
								<el-badge>{{ data.typeName }}</el-badge>
							</span>
							<span style="margin-left: 50px;" v-show="node.isCurrent">
								<el-button type="text" size="mini" @click.stop="() => append(data)"
										   icon="el-icon-plus"></el-button>
								<el-button type="text" size="mini" @click.stop="() => modify(node, data)"
										   icon="el-icon-edit"></el-button>
								<el-button type="text" size="mini" @click.stop="() => remove(node, data)"
										   icon="el-icon-delete"></el-button>
							</span>
						</span>
					</el-tree>
				</div>
				<el-container>
					<el-header height="50px" class="item-header">
						<div class="main-title">文章列表</div>
						<div>
							<el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple"
									   @click="handleDelete">删除
							</el-button>
							<el-button style="margin-right: 10px;" type="primary" icon="el-icon-plus" size="mini"
									   @click="handleArticleAdd">新增文章
							</el-button>
						</div>
					</el-header>
					<div class="app-container">
						<el-form ref="articleQueryForm" :inline="true" :model="queryParams" size="small"
								 label-width="80px">
							<el-form-item label="文章标题">
								<el-input v-model="queryParams.title" placeholder="请输入文章标题"></el-input>
							</el-form-item>
							<el-form-item label="作者">
								<el-input v-model="queryParams.author" placeholder="请输入作者"></el-input>
							</el-form-item>
							<el-form-item label="创建时间">
								<el-date-picker
									v-model="dateRange"
									size="small"
									style="width: 240px"
									value-format="yyyy-MM-dd"
									type="daterange"
									range-separator="-"
									start-placeholder="开始日期"
									end-placeholder="结束日期"
									:picker-options="pickerOptions"
								></el-date-picker>
							</el-form-item>
							<el-form-item label="审核状态">
								<el-select v-model="queryParams.approvalStatus" placeholder="请选择审核状态" :clearable="true">
									<el-option label="未审核" :value="0"/>
									<el-option label="一审通过" :value="1"/>
									<el-option label="二审通过" :value="2"/>
									<el-option label="审核未通过" :value="3"/>
								</el-select>
							</el-form-item>
							<el-form-item label="是否公开">
								<el-select v-model="queryParams.publicStatus" placeholder="请选择公开状态" :clearable="true">
									<el-option label="未公开" :value="0"/>
									<el-option label="已公开" :value="1"/>
								</el-select>
							</el-form-item>
							<el-form-item label="创作类型">
                <el-select v-model="queryParams.creationType" placeholder="请选择创作类型" :clearable="true">
                  <el-option label="原创" :value="0"/>
                  <el-option label="转载" :value="1"/>
                </el-select>
							</el-form-item>
              <el-form-item label="精选">
                <el-select v-model="queryParams.selection" placeholder="请选择精选类型" :clearable="true">
                  <el-option label="是" :value="0"/>
                  <el-option label="否" :value="1"/>
                </el-select>
              </el-form-item>
							<el-form-item>
								<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索
								</el-button>
								<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
							</el-form-item>
						</el-form>
						<el-table :data="articleList" style="width: 100%" v-loading="articleTableLoading"
								  @selection-change="handleSelectionChange">
							<el-table-column type="selection" width="55" align="center"/>
							<el-table-column type="index" :index="indexMethod" label="序号" width="50"></el-table-column>
							<el-table-column prop="title" label="标题" show-overflow-tooltip
											 width="250"></el-table-column>
							<el-table-column prop="articleId" label="文章ID" width="100"></el-table-column>
							<el-table-column prop="author" label="作者" width="100"></el-table-column>
							<el-table-column prop="typeName" show-overflow-tooltip label="分类"></el-table-column>
							<!-- <el-table-column prop="approvalUser" label="初审用户"></el-table-column> -->
							<el-table-column prop="reviewUser" label="审核用户"></el-table-column>
							<el-table-column prop="approvalStatus" label="审核状态" width="100">
								<template slot-scope="scope">
									<span v-if="scope.row.approvalStatus === 0"><el-tag type="info">未审核</el-tag></span>
									<span v-else-if="scope.row.approvalStatus === 1 && scope.row.reviewStatus === 0"><el-tag type="info">待审核</el-tag></span>
									<span v-else-if="scope.row.approvalStatus === 1 && scope.row.reviewStatus === 1"><el-tag
										type="success">审核通过</el-tag></span>
									<span v-else-if="scope.row.approvalStatus === 3"><el-tag
										type="warning">审核未通过</el-tag></span>
									<span v-else-if="scope.row.approvalStatus === 1 && scope.row.reviewStatus === 3"><el-tag type="warning">审核未通过</el-tag></span>
								</template>
							</el-table-column>
              <el-table-column prop="publicStatus" label="创作类型" width="100">
                <template slot-scope="scope">
                  <span v-if="scope.row.creationType === 0"><el-tag type="">原创</el-tag></span>
                  <span v-if="scope.row.creationType === 1"><el-tag type="success">转载</el-tag></span>
                </template>
              </el-table-column>
			  <el-table-column prop="publicStatus" label="发布状态" width="100">
                <template slot-scope="scope">
                  <span v-if="scope.row.status === 1"><el-tag type="">草稿</el-tag></span>
                  <span v-if="scope.row.status === 0"><el-tag type="success">发布</el-tag></span>
                </template>
              </el-table-column>
							<el-table-column prop="publicStatus" label="公开状态" width="100">
								<template slot-scope="scope">
									<span v-if="scope.row.publicStatus === 0"><el-tag type="">未公开</el-tag></span>
									<span v-if="scope.row.publicStatus === 1"><el-tag type="success">已公开</el-tag></span>
								</template>
							</el-table-column>
              <el-table-column prop="selection" label="精选" width="100">
                <template slot-scope="scope">
                  <el-switch
                    v-model="scope.row.selection"
                    active-color="#ff4949"
                    @change="(value) => handleArticleSelectionChange(value, scope.row)"
                    :active-value="0"
                    :inactive-value="1"
                  ></el-switch>
                </template>
              </el-table-column>
							<el-table-column prop="pageView" label="阅读量"></el-table-column>
							<el-table-column prop="collection" label="收藏量"></el-table-column>
							<el-table-column prop="createTime" label="创建时间" width="100">
								<template slot-scope="scope">{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}
								</template>
							</el-table-column>
							<el-table-column label="操作" fixed="right">
								<template slot-scope="scope">
									<el-dropdown>
								    <span class="el-dropdown-link">
										操作<i class="el-icon-arrow-down el-icon--right"></i>
								    </span>
										<el-dropdown-menu slot="dropdown">
											<el-dropdown-item @click.native="viewArticle(scope.row)"><i
												class="el-icon-view"></i>查看
											</el-dropdown-item>
											<el-dropdown-item @click.native="openEditAuthor(scope.row)"><i
												class="el-icon-edit"></i>修改作者
											</el-dropdown-item>
											<el-dropdown-item @click.native="openEditTime(scope.row)"><i
												class="el-icon-time"></i>修改时间
											</el-dropdown-item>
											<el-dropdown-item
												v-if="scope.row.publicStatus===0 && scope.row.reviewStatus===1"
												@click.native="publicArticle(scope.row, 1)"><i
												class="el-icon-success"></i>公开文章
											</el-dropdown-item>
											<el-dropdown-item v-if="scope.row.publicStatus===1"
															  @click.native="publicArticle(scope.row, 0)"><i
												class="el-icon-error"></i>取消公开
											</el-dropdown-item>
											<el-dropdown-item @click.native="approval(scope.row)"
															  v-if="scope.row.approvalStatus==0&&scope.row.reviewStatus==0">
												<i class="el-icon-error"></i>文章一审
											</el-dropdown-item>
											<el-dropdown-item disabled
															  v-if="scope.row.approvalStatus==1&&scope.row.reviewStatus==0">
												<i class="el-icon-error"></i>一审已完成
											</el-dropdown-item>
											<el-dropdown-item @click.native="review(scope.row)"
															  v-if="scope.row.approvalStatus==1&&scope.row.reviewStatus==0">
												<i class="el-icon-error"></i>文章二审
											</el-dropdown-item>
											<el-dropdown-item disabled
															  v-if="scope.row.approvalStatus==1&&scope.row.reviewStatus==1">
												<i class="el-icon-error"></i>文章已完成审核
											</el-dropdown-item>
											<el-dropdown-item disabled v-if="scope.row.approvalStatus==3"><i
												class="el-icon-error"></i>文章一审未通过
											</el-dropdown-item>
											<el-dropdown-item disabled
															  v-if="scope.row.approvalStatus==1&&scope.row.reviewStatus==3">
												<i class="el-icon-error"></i>文章二审未通过
											</el-dropdown-item>
											<el-dropdown-item @click.native="handleDelete(scope.row)">
												<i class="el-icon-delete"></i>删除
											</el-dropdown-item>
										</el-dropdown-menu>
									</el-dropdown>
								</template>
							</el-table-column>
						</el-table>
						<pagination
							v-show="total>0"
							:total="total"
							:page.sync="queryParams.pageNum"
							:limit.sync="queryParams.pageSize"
							@pagination="getArticleList"
						/>
					</div>
				</el-container>
			</div>
			<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="50%">
			<span>
				<el-form :rules="rules" ref="ruleForm" :model="form" label-width="80px">
					<el-form-item label="上级分类">
						<el-input v-model="form.parentName" :readonly="true"></el-input>
					</el-form-item>
					<el-form-item label="分类名称" prop="typeName">
						<el-input v-model="form.typeName" placeholder="请输入分类名称..."></el-input>
					</el-form-item>
				</el-form>
			</span>
				<span slot="footer" class="dialog-footer">
	    		<el-button @click="dialogVisible = false">取 消</el-button>
	    		<el-button type="primary" @click="handleConfirm">确 定</el-button>
	  		</span>
			</el-dialog>
			<!-- 添加或修改文章对话框 -->
			<el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
				<el-form ref="articleForm" :model="articleForm" :rules="articleRules" label-width="100px">
					<el-row>
						<el-col :span="24">
							<el-form-item label="文章标题" prop="title">
								<el-input v-model="articleForm.title" placeholder="请输入文章标题"/>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item label="状态" prop="status">
								<el-radio-group v-model="articleForm.status">
									<el-radio :label="1">草稿</el-radio>
									<el-radio :label="0">发布</el-radio>
								</el-radio-group>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item label="文章类型:" prop="articleType">
								<el-cascader ref="myCascader"
											 :props="{ value: 'typeId', label: 'typeName', multiple: true }"
											 v-model="articleForm.articleType" style="width: 100%;"
											 :show-all-levels="false" :options="dataTree" @change="handleChange"
											 :clearable="true"></el-cascader>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item label="内容" prop="content">
								<Editor v-model="articleForm.content" @setThumbnail="setThumbnail"/>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
				<div slot="footer" class="dialog-footer" style="padding-top:30px">
					<el-button type="primary" @click="submitForm">确 定</el-button>
					<el-button @click="cancel">取 消</el-button>
				</div>
			</el-dialog>
			<!-- 添加或修改文章对话框 -->
			<el-dialog :title="title" :visible.sync="dialogByES" width="780px" append-to-body>
				<el-form ref="elForm" :model="formData" :rules="rulestwo" size="medium" label-width="100px">
					<el-form-item label="审核状态" prop="approvalStatus">
						<el-radio-group v-model="formData.approvalStatus" size="medium">
							<el-radio v-for="(item, index) in approvalStatusOptions" :key="index" :label="item.value"
									  :disabled="item.disabled">{{ item.label }}
							</el-radio>
						</el-radio-group>
					</el-form-item>
					<el-form-item label="文章类型" prop="classify">
						<el-select v-model="formData.classify" placeholder="请选择文章类型" clearable :style="{width: '100%'}">
							<el-option v-for="(item, index) in classifyOptions" :key="index" :label="item.label"
									   :value="item.value" :disabled="item.disabled"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="一审文章修改类型" prop="classify2" v-if="approvalDoctorIdFlag">
						<el-select v-model="formData.classify2" placeholder="请选择文章修改类型" clearable
								   :style="{width: '100%'}">
							<el-option v-for="(item, index) in approvalDoctorOptions" :key="index" :label="item.label"
									   :value="item.value" :disabled="item.disabled"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="审核意见" prop="reviewSpec">
						<el-input v-model="formData.reviewSpec" type="textarea" placeholder="请输入审核意见"
								  :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
					</el-form-item>
				</el-form>
				<div slot="footer">
					<el-button @click="close">取消</el-button>
					<el-button type="primary" @click="handelConfirm">确定</el-button>
				</div>
				<!--				<div slot="footer" class="dialog-footer" style="padding-top:30px">-->
				<!--					<el-button type="primary" @click="ershenYJTG()">审核通过</el-button>-->
				<!--					<el-button @click="ershenYJQX()">审核不通过</el-button>-->
				<!--				</div>-->
			</el-dialog>
			<!-- 修改作者弹出框 -->
			<el-dialog title="修改作者" :visible.sync="editAuthor.visible" width="30%" append-to-body>
				<el-select v-model="editAuthor.doctorId" placeholder="请选择作者" clearable filterable>
					<el-option
						v-for="item in doctorList"
						:key="item.doctorId"
						:label="item.doctorName"
						:value="item.doctorId">
					</el-option>
				</el-select>
				<span slot="footer" class="dialog-footer">
			    	<el-button @click="editAuthor.visible = false">取 消</el-button>
			    	<el-button type="primary" @click="doEditAuthor">确 定</el-button>
			  	</span>
			</el-dialog>
			<el-dialog title="修改时间" :visible.sync="editTime.visible" width="30%" append-to-body>
				<el-date-picker
					v-model="editTime.createTime"
					type="datetime"
					placeholder="选择日期时间"
					align="right"
					value-format="yyyy-MM-dd HH:mm:ss"
					:picker-options="timePickerOptions">
				</el-date-picker>
				<span slot="footer" class="dialog-footer">
			    	<el-button @click="editTime.visible = false">取 消</el-button>
			    	<el-button type="primary" @click="doEditTime">确 定</el-button>
			  	</span>
			</el-dialog>
		</template>
		<template v-else>
			<div key="inside">
				<el-page-header @back="goBack" content="详情页面">
				</el-page-header>
				<h1 style="text-align: center">{{ currentRow.title }}</h1>
				<div v-html="currentRow.content" style="padding: 20px 50px 50px 50px;overflow: hidden;"></div>
				<div style="display: flex;justify-content: center;align-items: center;">
					<video width="80%" height="300" controls v-if="currentRow.videoUrl">
						<source :src="ossUrl + currentRow.videoUrl" type="video/mp4">
						您的浏览器不支持 HTML5 video 标签。
					</video>
				</div>
			</div>
		</template>
	</div>
</template>

<script>
import {listType, addType, updateType, delType} from '@/api/hospital/articleType'
import {GetDoctorById, getAllDoctor} from '@/api/doctor/index'
import {addPoint, listPointAll} from '@/api/point/point'
import {EditArticleList, InsertArticleList, GetArticleList, DeleteArticleList, EditAuthor} from "@/api/healthy/article";
import Editor from '@/components/Editor';
import {mapGetters} from "vuex";

export default {
	components: {
		Editor
	},
	data() {
		return {
			dataTree: [],
			dialogVisible: false,
			dialogByES: false,
			dialogTitle: '新增',
			options: [],
			optionsTwo: [],
			// 选中数组
			ids: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			form: {
				typeId: undefined,
				parentId: undefined,
				typeName: undefined,
				parentName: undefined
			},
			rules: {
				typeName: [
					{required: true, message: '请输入活动名称', trigger: 'blur'}
				]
			},
			tableData: [],
			reviewSpec: "",
			open: false,
			loading: false,
			// 表单参数
			articleForm: {
				title: undefined,
				status: 0,
				content: undefined,
				articleType: []
			},
			// 表单校验
			articleRules: {
				title: [
					{required: true, message: "文章标题不能为空", trigger: "blur"}
				],
				articleType: [
					{type: 'array', required: true, message: "文章类型不能为空", trigger: "change"}
				],
				content: [
					{required: true, message: "文章内容不能为空", trigger: "blur"}
				]
			},
			// 弹出层标题
			title: "",
			articleId: undefined,
			articleTitle: undefined,
			doctorId: undefined,
			point: undefined,
			pointUpperLimit: undefined,
			typeValues: [],
			typeLabels: [],
			thumbnail: undefined,
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				title: undefined,
				typeId: undefined,
				publicStatus: undefined,
				approvalStatus: undefined,
				creationType: undefined,
        selection: undefined,
				orderByColumn: 'create_time',
				isAsc: 'desc'
			},
			articleList: [],
			articleTableLoading: false,
			total: 0,
			flag: true,
			currentRow: {},
			approvalDoctorIdFlag: false,
			approvalDoctorId: undefined,
			baseUrl: process.env.VUE_APP_BASE_API,
			ossUrl: this.$ossUrl,
			formData: {
				approvalStatus: undefined,
				classify: undefined,
				reviewSpec: undefined,
				classify2: undefined,
			},
			rulestwo: {
				approvalStatus: [{
					required: true,
					message: '审核状态不能为空',
					trigger: 'change'
				}],
				classify: [{
					required: true,
					message: '请选择文章类型',
					trigger: 'change'
				}],
				classify2: [{
					required: true,
					message: '请选择文章修改类型',
					trigger: 'change'
				}],
				reviewSpec: [{
					required: true,
					message: '请输入审核意见',
					trigger: 'blur'
				}],
			},
			approvalStatusOptions: [{
				"label": "通过",
				"value": 2
			}, {
				"label": "驳回",
				"value": 3
			}],
			approvalDoctorOptions: [],
			classifyOptions: [],
			dateRange: [],
			pickerOptions: {
				shortcuts: [{
					text: '最近一周',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近一个月',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近三个月',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
						picker.$emit('pick', [start, end]);
					}
				}]
			},
			editAuthor: {
				visible: false,
				doctorId: undefined,
				articleId: undefined
			},
			editTime: {
				visible: false,
				createTime: undefined,
				articleId: undefined
			},
			doctorList: [],
			timePickerOptions: {
				shortcuts: [{
					text: '今天',
					onClick(picker) {
						picker.$emit('pick', new Date());
					}
				}, {
					text: '昨天',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() - 3600 * 1000 * 24);
						picker.$emit('pick', date);
					}
				}, {
					text: '一周前',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
						picker.$emit('pick', date);
					}
				}]
			}
		};
	},
	computed: {
		...mapGetters(['name', 'doctor', 'userid'])
	},
	mounted() {
		this.getList()
		this.getArticleList()
		this.pointListAll()
		this.getDoctorList()
	},
	methods: {
		getDoctorList() {
			getAllDoctor().then(res => {
				this.doctorList = res.data;
			})
		},
		pointListAll() {
			listPointAll().then(res => {
				for (var i = 0; i < res.data.length; i++) {
					var pointList = {
						"label": "",
						"value": ""
					}
					if (res.data[i].parentId == 49) {
						pointList.label = res.data[i].serviceName
						pointList.value = res.data[i].serviceId
						pointList.point = res.data[i].point
						this.approvalDoctorOptions.push(pointList)
					}
					if (res.data[i].parentId == 47) {
						pointList.label = res.data[i].serviceName
						pointList.value = res.data[i].serviceId
						pointList.point = res.data[i].point
						this.classifyOptions.push(pointList)
					}
				}
			})
		},
    handleArticleSelectionChange(value, row) {
      this.articleTableLoading = true;
      console.log(value)
      EditArticleList({ articleId: row.articleId, selection: value }).then(res => {
        if (res.code === 200) {
          this.articleTableLoading = false;
          this.msgSuccess('操作成功');
          this.getArticleList();
        }
      })
    },
		handleSelectionChange(selection) {
			this.ids = selection.map(item => item.articleId)
			this.single = selection.length != 1
			this.multiple = !selection.length
		},
		approval(row) {
			let articleId = row.articleId
			this.$confirm('是否确认审核通过文章编号为"' + articleId + '"的数据项?', "警告", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning"
			}).then(() => {
				EditArticleList({
					articleId: articleId,
					approvalStatus: 1,
					approvalDoctorId: this.name === 'admin' ? this.userid : this.doctor.doctorId,
					isTop: 0,
					approvalUser: this.name === 'admin' ? "逸创胜美" : (this.doctor.doctorName + '--' + this.titleFilter(this.doctor.title) + '--' + this.doctor.hospitalName),
					reviewStatus: 1,
					reviewUser: this.name === 'admin' ? "逸创胜美" : (this.doctor.doctorName + '--' + this.titleFilter(this.doctor.title) + '--' + this.doctor.hospitalName),
				}).then(response => {
					if (response.code === 200) {
						this.msgSuccess("审核成功");
						this.getList()
						this.getArticleList();
					}
				});
			})
		},
		publicArticle(row, status) {
			let articleId = row.articleId
			let message = status === 1 ? '是否确认公开文章编号为' : '是否确认取消公开文章编号为'
			this.$confirm(message + articleId + '"的数据项?', "警告", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning"
			}).then(() => {
				EditArticleList({
					articleId: articleId,
					publicStatus: status
				}).then(response => {
					if (response.code === 200) {
						this.msgSuccess("操作成功");
						this.getList()
						this.getArticleList();
					}
				});
			})
		},
		//二审意见通过
		ershenYJTG() {
			EditArticleList({
				articleId: this.articleId,
				reviewSpec: this.formData.reviewSpec,
				relatedTopics: this.articleTitle,
				reviewStatus: 1,
				isTop: 0,
				reviewUser: this.name === 'admin' ? "逸创胜美" : (this.doctor.doctorName + '--' + this.titleFilter(this.doctor.title) + '--' + this.doctor.hospitalName)
			}).then(response => {
				if (response.code === 200) {
					this.msgSuccess("审核成功");
					//积分事件
					if (this.doctorId != null) {
						this.pointAction(this.doctorId);
					}
					this.dialogByES = false;
					//this.getList()
					this.getArticleList();
				}
			});
		},
		//二审意见不通过
		ershenYJQX() {
			EditArticleList({
				articleId: this.articleId,
				reviewSpec: this.formData.reviewSpec,
				relatedTopics: this.articleTitle,
				reviewStatus: 3,
				isTop: 0,
				reviewUser: this.name === 'admin' ? "逸创胜美" : (this.doctor.doctorName + '--' + this.titleFilter(this.doctor.title) + '--' + this.doctor.hospitalName)
			}).then(response => {
				if (response.code === 200) {
					this.msgSuccess("审核成功");
					this.dialogByES = false;
					// this.getList()
					this.getArticleList();
				}
			});
		},
		close() {
			this.dialogByES = false;
		},
		handelConfirm() {
			this.getDictByType();//积分主逻辑
		},
		review(row) {
			this.articleId = row.articleId
			this.articleTitle = row.title;
			this.doctorId = row.doctorId
			if (row.approvalDoctorId != null) {
				this.approvalDoctorIdFlag = true
				this.approvalDoctorId = row.approvalDoctorId
			}
			this.dialogByES = true;
			// this.$confirm('是否确认审核通过文章编号为"' + articleId + '"的数据项?', "警告", {
			//   confirmButtonText: "确定",
			//   cancelButtonText: "取消",
			//   type: "warning"
			// }).then(() => {

			// })
		},
		append(data) {
			this.dialogTitle = "新增";
			this.dialogVisible = true;
			this.form.parentId = data.typeId;
			this.form.parentName = data.typeName;
		},
		remove(node, data) {
			if (node.isLeaf) {
				this.$confirm('此操作将删除改分类, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					delType(data.typeId).then(res => {
						if (res.code == 200) {
							this.msgSuccess('您的操作已提交成功');
							this.getList();
						}
					})
				});
			} else {
				this.msgWarn('当前分类下还有子分类，请删除子分类后再执行删除操作');
			}
		},
		modify(node, data) {
			this.dialogTitle = "修改";
			this.dialogVisible = true;
			this.form.typeId = data.typeId;
			this.form.parentId = node.parent.data.typeId ? node.parent.data.typeId : -1;
			this.form.parentName = node.parent.data.typeName ? node.parent.data.typeName : -1;
			this.form.typeName = data.typeName;
		},
		handleAdd() {
			this.dialogTitle = "新增";
			this.dialogVisible = true;
			this.form.parentId = -1;
			this.form.parentName = -1;
		},
		/** 新增按钮操作 */
		handleArticleAdd() {
			this.reset();
			this.open = true;
			this.title = "添加文章";
		},
		handleConfirm() {
			this.$refs.ruleForm.validate((valid) => {
				if (valid) {
					if (this.dialogTitle == "新增") {
						addType(this.form).then(res => {
							this.handleSuccess(res)
						})
					} else {
						updateType(this.form).then(res => {
							this.handleSuccess(res)
						})
					}
				} else {
					return false;
				}
			});
		},
		getList() {
			this.loading = true;
			listType().then(response => {
				this.dataTree = this.handleTree(response.data, "typeId");
				this.loading = false;
			})
		},
		reset() {
			this.form = {
				parentId: undefined,
				typeName: undefined,
				parentName: undefined
			}
			this.articleForm = {
				title: undefined,
				status: 0
			}
		},
		handleChange() {
			let values = [];
			let labels = [];
			let checkedNodes = this.$refs.myCascader.getCheckedNodes();
			for (let i = 0; i < checkedNodes.length; i++) {
				values.push(checkedNodes[i].value);
				labels.push(checkedNodes[i].label);
			}
			this.typeValues = values
			this.typeLabels = labels
		},
		handleSuccess(res) {
			if (res.code == 200) {
				this.getList();
				this.msgSuccess('您的操作已提交成功');
				this.dialogVisible = false;
				this.reset();
			}
		},
		submitForm: function () {
			this.$refs["articleForm"].validate(valid => {
				if (valid) {
					if (this.articleForm.articleId != undefined) {
						EditArticleList(this.form).then(response => {
							if (response.code === 200) {
								this.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							}
						});
					} else {
						let params = {
							title: this.articleForm.title,
							typeId: this.typeValues.join(','),
							typeName: this.typeLabels.join(','),
							status: this.articleForm.status,
							content: this.articleForm.content,
							author: '逸创胜美',
							thumbnail: this.thumbnail,
							approvalStatus: 0,
							reviewStatus: 0
						}
						InsertArticleList(params).then(response => {
							if (response.code === 200) {
								this.msgSuccess("新增成功");
								this.open = false;
								this.getArticleList()
							}
						});
					}
				}
			});
		},
		cancel() {
			this.open = false;
			this.reset();
		},
		setThumbnail(thumbnail) {
			this.thumbnail = thumbnail;
		},
		getArticleList() {
			this.articleTableLoading = true;
			GetArticleList(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
				this.articleList = res.rows;
				this.total = res.total;
				this.articleTableLoading = false;
			})
		},
		viewArticle(row) {
			this.currentRow = row;
			this.flag = !this.flag;
		},
		openEditAuthor(row) {
			this.editAuthor.visible = true;
			this.editAuthor.articleId = row.articleId;
		},
		openEditTime(row) {
			this.editTime.visible = true;
			this.editTime.articleId = row.articleId;
		},
		doEditAuthor() {
			EditAuthor({articleId: this.editAuthor.articleId, doctorId: this.editAuthor.doctorId}).then(res => {
				if (res.code === 200) {
					this.$message.success("操作成功");
					this.getArticleList();
					this.editAuthor.visible = false;
				}
			})
		},
		doEditTime() {
			EditArticleList({articleId: this.editTime.articleId, createTime: this.editTime.createTime}).then(res => {
				if (res.code === 200) {
					this.$message.success("操作成功");
					this.getArticleList();
					this.editTime.visible = false;
				}
			})
		},
		goBack() {
			this.flag = !this.flag;
		},
		handleClickNode(data) {
			this.queryParams.typeId = data.typeId;
			this.getArticleList();
		},
		indexMethod(index) {
			return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
		},
		handleDelete(row) {
			let articleId = row.articleId || this.ids
			this.$confirm('是否确认删除文章编号为"' + articleId + '"的数据项?', "警告", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning"
			}).then(function () {
				return DeleteArticleList(articleId);
			}).then(() => {
				this.getList();
				this.getArticleList();
				this.msgSuccess("删除成功");
			}).catch(function () {
			});
		},
		//积分主逻辑
		pointAction(doctorId) {
			//获取积分
			GetDoctorById(doctorId).then(res => {
				if (res.code == 200) {
					if (res.data.sunshine == 1) {//是否为阳光工程医生
						let params = {
							pointEventName: '视频、文章、 图片上传与管理-文档上传-' + this.options.label,
							pointEventValue: parseInt(this.options.point),
							doctorId: doctorId,
							createBy: doctorId
						}
						addPoint(params);
					}
				}
			})
		},
		//获取积分事件
		getDictByType() {
			if (this.approvalDoctorIdFlag) {//存在一审医生id
				for (var i = 0; i < this.approvalDoctorOptions.length; i++) {
					if (this.approvalDoctorOptions[i].value === this.formData.classify2) {
						this.optionsTwo = this.approvalDoctorOptions[i]
						break;
					}
				}
				this.pointActiontTWO(this.approvalDoctorId)
			}
			for (var i = 0; i < this.classifyOptions.length; i++) {
				if (this.classifyOptions[i].value === this.formData.classify) {
					this.options = this.classifyOptions[i]
					break;
				}
			}
			if (this.formData.approvalStatus == 2) {
				this.ershenYJTG();
			} else if (this.formData.approvalStatus == 3) {
				this.ershenYJQX()
			}
		},
		//积分主逻辑
		pointActiontTWO(doctorId) {
			//获取积分
			GetDoctorById(doctorId).then(res => {
				if (res.code == 200) {
					if (res.data.sunshine == 1) {//是否为阳光工程医生
						const pointEventName = this.optionsTwo.label ? '视频、文章、 图片上传与管理-专家评审-' + this.optionsTwo.label : '';
						let params = {
							pointEventName: pointEventName,
							relatedTopics: this.articleTitle,
							pointEventValue: parseInt(this.optionsTwo.point),
							doctorId: doctorId,
							createBy: doctorId
						}
						addPoint(params);
					}
				}
			})
		},
		resetQuery() {
			this.queryParams.title = undefined;
			this.dateRange = [];
			this.handleQuery();
		},
		handleQuery() {
			this.getArticleList()
		},
		titleFilter(text) {
			if (text == 'zhuyuan_doctor') {
				return '住院医师';
			} else if (text == 'zhuzhi_doctor') {
				return '主治医师';
			} else if (text == 'fuzhuren_doctor') {
				return '副主任医师';
			} else if (text == 'zhuren_doctor') {
				return '主任医师';
			} else if (text == 'ys02') {
				return '主任中医师';
			} else if (text == 'ys04') {
				return '副主任中医师';
			} else if (text == 'ys06') {
				return '主治中医师';
			} else if (text == 'ys08') {
				return '住院中医师';
			} else if (text == 'ys09') {
				return '助理医师';
			} else if (text == 'ys10') {
				return '实习医师';
			} else if (text == 'ys11') {
				return '在校学生';
			} else if (text == 'ys12') {
				return '其他';
			}
			return text;
		}
	}
}
</script>

<style lang="scss" scoped>
.el-dropdown-link {
	cursor: pointer;
	color: #409EFF;
}

.el-icon-arrow-down {
	font-size: 12px;
}

.content {
	margin: -20px;
	height: calc(100% + 40px);
	display: flex;

	.aside {
		flex: 0 280px;
		position: relative;
		box-shadow: 1px 0 0 rgba(0, 21, 41, 0.08);

		.tree-header {
			position: absolute;
			height: 50px;
			width: 100%;
			font-size: 36 upx;
			line-height: 30px;
			font-family: PingFangSC-Regular;
			padding: 10px 22px;
			box-shadow: 0px 2px 4px rgba(0, 21, 41, 0.08);
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-sizing: border-box;
		}

		.tree {
			margin-top: 55px;
			font-size: 28 upx;

			> > > .tree-node {
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 28 upx;
				padding-right: 8px;

				.el-button + .el-button {
					margin-left: 3px;
				}

			}
		}

	}

	.service-item {
		flex: 1;
	}
}

.el-icon-folder {
	color: #519eff;
}

.item-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 6px 20px;
	box-shadow: 0px 2px 4px rgba(0, 21, 41, 0.08);

	.main-title {
		font-family: PingFangSC-Light;
		line-height: 20px;
		font-size: 32 upx;
		display: inline-block;
		margin-right: 12px;
		padding-left: 10px;
		border-left: 4px solid #1890FF;
	}
}

</style>
